﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ImageUploaderComponent.Extensions;

namespace ImageUploaderComponent.Data {
    public class DataStorageMediator : IDisposable {
        private IDataService service = new  IsolatedStorageDataService();



        public UploaderViewModel GetViewModelsForImages(int skillId){
            var newModel = new UploaderViewModel();
            List<MediaData> images = service.GetImagesForSkill(skillId);
            if (images.Count > 0) {
                var mediaList = images.Select(i => new ImageDataViewModel((ImageData)i)).ToObservable();
                newModel.ImageDataList = mediaList;
            }
            return newModel;
        }


        public void Dispose(){
            service.Dispose();
        }

        public void BeginUploadFile(MediaData data, Action<Guid, double> uploadProgessChanged, Action<Guid, ResultStruct> uploadComplete){
            service.BeginUploadFile(data,uploadProgessChanged,uploadComplete);
        }

        public void CommitImageMetaData(UploaderViewModel uploaderViewModel, int skillKeyId){
           ((IsolatedStorageDataService) service).CommitImageMetaData(uploaderViewModel,skillKeyId);
            service.Commit(Guid.NewGuid(), uploaderViewModel.ImageDataList.Select(i => i.Key).ToList());

        }

        public void DeleteFile(ImageDataViewModel item){
            service.DeleteFile(item.Key);
        }

        public void ArchiveItem(ImageDataViewModel item){
            service.ArchiveItem(item.Key);
        }
    }
}
